package com.sunkyc.framework.mq.reqmq;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.lmax.disruptor.EventHandler;
import com.sunkyc.framework.system.entity.SysLoginLog;
import com.sunkyc.framework.system.entity.SysReqLog;
import com.sunkyc.framework.system.service.SysLoginLogService;
import com.sunkyc.framework.system.service.SysReqLogService;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ReqLogEventHandler implements EventHandler<ReqMessageModel> {
    @Override
    public void onEvent(ReqMessageModel event, long sequence, boolean endOfBatch) {
        try {
            if (event != null) {
                SysReqLog reqLog = JSONUtil.toBean(event.getMessage(), SysReqLog.class);
                if(ObjectUtil.isNotNull(reqLog)){
                    SysReqLogService sysLoginLogService = SpringUtil.getBean(SysReqLogService.class);
                    sysLoginLogService.save(reqLog);
                }
            }
        } catch (Exception e) {

        }
    }
}
